import socket
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = ('192.168.31.173', 9999)
server_socket.bind(address)
server_socket.listen(5)
print("开始监听", address)
client_socket, address = server_socket.accept()
print("我们收到了{}的连接".format(address))
while True:
    data = client_socket.recv(1024)
    if not data:
        break
    print("客户端说：{}".format(data.decode()))  # 解码收到的数据
    response = input("服务端回应：")
    client_socket.send(response.encode())  # 发送回应时需要编码
client_socket.close()
server_socket.close()  # 记得关闭服务
